<template>
    <div class="content">
        <form action="#">
            <div>
                账号:<input type="text" v-model="username">
            </div>
            <div>
                密码: <input type="password" v-model="password">
            </div>
            <input type="submit" value="登录" @click="login">
        </form>
    </div>
</template>
<script setup>
import { ref, onMounted } from 'vue'
import { useRoute, useRouter } from 'vue-router';
const username = ref('')
const password = ref('')
const router = useRouter()
const route = useRoute()
const login = () => {
    const userInfo = JSON.parse(window.localStorage.getItem('userInfo'))

    if (userInfo) {
        if (userInfo.username == username.value && userInfo.password == password.value) {
            window.localStorage.setItem('token', username.value + password.value)
            router.push('/home')
        } else {
            alert('用户名或密码不正确')
        }
    } else {
        alert('该用户尚未注册')
    }
}
onMounted(() => {
    username.value = route.query.username
    password.value = route.query.password
})
</script>
<style scoped>
.content {
    margin: auto;
    text-align: center;
}
</style>